package com.sikaryofficial.backend.config;

import cn.hutool.core.text.CharSequenceUtil;
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Configuration;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;


/**
 * @author : qinjinyuan
 * @desc : 文章资讯相关配置
 * @date : 2024/06/03 13:36
 */
@Getter
@Setter
@Configuration
@RefreshScope
@ConfigurationProperties(prefix = "hismk.backend.article")
@Slf4j
public class ArticleConfig {
    /**
     * 小口吸对应国家 28个
     */
    private String smallMouthCountry;

    public boolean findSmallMouthCountry(String isoCountryCode) {
        if(CharSequenceUtil.isBlank(smallMouthCountry)){
            log.error("small mouth country is empty");
            return false;
        }
        if(CharSequenceUtil.isBlank(isoCountryCode)){
            log.warn("input is empty");
            return false;
        }
        Set<String> smallMouthCountries = Arrays.stream(smallMouthCountry.split(","))
                .collect(Collectors.toCollection(HashSet::new));
        return smallMouthCountries.contains(isoCountryCode.toUpperCase(Locale.ROOT));
    }

}
